define({
	title: "oneMap",
	body: `
	<div class='body'>
	<div class='topHeader'>
		<span class='top-pageLogo'>重庆市农业气象精细化智能服务平台</span>
		<span class='top-pageName'>运行监控子系统</span>
		<div class='top-homebar'>
			<span class='nav-home'>首页</span>
			<a class='nav-map'  data-panel="pageOneMap">地图</a>
			<label>当前区域：
				<span id="addr-show02">重庆</span>
			</label>
		</div>
	</div>
	<div style="backgrund:white" id="main" class="main">
        <div class="wrap">
            <div id="map" class="map"></div><!-- 地图 -->
            <div class="wrap_piece"><!-- 实例块 -->
                <div class="wp wp_shadow wrap_menu">
                    <div class="menu">
                        <i class="fa fa-navicon" aria-hidden="true"></i>
                    </div>
                    <div class="search-text">
                        <input type="text" name="search-text" value="" placeholder="请输入地市名">
                    </div>
                    <div class="search-btn">
                        <i class="fa fa-search" aria-hidden="true"></i>
                    </div>
                </div><!-- 菜单 -->
                <div class="wp wrap_title">
                    <div class="wp_shadow">
                        <h>重庆市</h>
                        <span></span>
                    </div>
                </div><!-- 渲染名 -->
                <div class="wp wrap_colorCode">
                    <ul class="wp_shadow"></ul>
                </div><!-- 色标 -->
                <div class="wp wp_shadow wrap_basemap">
                    <div class="mapChange basic">
                        <h>矢量</h>
                    </div>
                    <div class="mapChange image">
                        <h>影像</h>
                    </div>
                    <div class="mapChange terrain">
                        <h>地形</h>
                    </div>
                </div><!-- 底图 -->
                <div class="wp wrap_timeScale">
                    <div class="timeBox wp_shadow">
                        <div class="head">
                            <div class="nowTime">
                                <input type="text" name="formDate" id="formDate">
                            </div>
                            <ul class="btnOpt">
                                <li class="prevOpt">
                                    <i class="fa fa-angle-left" aria-hidden="true"></i>
                                </li>
                                <li class="autoPlay">
                                    <i class="fa fa-play" aria-hidden="true"></i><!-- pause -->
                                </li>
                                <li class="nextOpt">
                                    <i class="fa fa-angle-right" aria-hidden="true"></i>
                                </li>
                            </ul>
                        </div>
                        <div class="content">
                            <div class="scale"><i></i></div>
                            <ul class="timeList"></ul>
                        </div>
                    </div>
                </div><!-- 时间尺 -->
                <div class="wp wrap_zoomPosition">
                    <div class="btn wp_shadow position">
                        <i></i>
                    </div>
                    <div class="zoom wp_shadow">
                        <div class="btn zoomEnlarge">
                            <i class="fa fa-plus" aria-hidden="true"></i>
                        </div>
                        <div class="btn zoomShrink">
                            <i class="fa fa-minus" aria-hidden="true"></i>
                        </div>
                    </div>
                </div><!-- 缩放定位 -->
            </div>
        </div>
        <div class="sidebar">
            <div class="sideBox">
                <div class="head">
                    <h>一张图</h>
                    <span class="back">
                        <i class="fa fa-angle-double-left" aria-hidden="true"></i>
                    </span>
                </div>
                <div class="list tree">
                    <ul></ul>
                </div>
                <div class="list setup">
                    <ul>
                        <li class="colorCode">
                            <h>色标</h>
                            <input type="checkbox" checked="checked">
                            <span class="checkbox"></span>
                        </li>
                        <li class="titleBg">
                            <h>标题背景</h>
                            <input type="checkbox" checked="checked">
                            <span class="checkbox"></span>
                        </li>
                        <li class="boundaries">
                            <h>行政边界</h>
                            <input type="checkbox" checked="checked">
                            <span class="checkbox"></span>
                        </li>
                    </ul>
                </div>
            </div>
		</div><!-- 侧边栏 -->
		</div>
    </div>`,
	init: function(pageData) {
        var $view = this
		// $('.main', $view).trigger('spa:scroll')
		// 获取hash
		function getHash(url) {
		  url = url || location.href
		  return url.replace(/^[^#]*#?\/?(.*)\/?$/, '$1')
		}
		$view.on('click', '.nav-map', function(event) {
		  	event.preventDefault()
			  $doc.trigger("spa:navigate", {
				hash: "pageOneMap"
			  })    
		})
		
		$view.on('click','.nav-home',function(event){
			event.preventDefault();
			$doc.trigger("spa:navigate", {
				hash: ""
			})  
		})

		$('#addr-show02').click(function(){
			/*自动加载省份列表*/
			require(['areajs'], function (area) {
				area.initAreaPanel();
			})
		})
	},
	
	afteropen: function () {
		// ----------------------------
//     // // /    //   // // //
//    //         //   //
//   // //      //   // // //
//        //   //   //      //
//       //   //    //      //
// // //     //      // // //
// ----------------------------
// -         mapView          -
// ----------------------------
(function(ב) {
    // 开启严格模式
    "use strict";
    
	// 初始化函数
	ב.map = null;
	ב.layer1 = null;
	ב.layer2 = null;
	ב.layer3 = null;
	ב.layer4 = null;
    ב.layer5 = null;
	ב.selectFeature = null;
	ב.selectFeatureLayers = [];
	ב.cleanMapLayersByName = null;
	ב.mapBounds = null;
	ב.mapStroke = null;
	ב.borderUrl = 'http://www.ynpasc.cn/onemap/services/coordinates/getLineByCode';
	ב.getLayerJson = null;
    ב.getLayerJsonUrl = 'http://112.74.171.47:8080/Geojson/yunnan/changguiyaosu/5/';
    ב.getLayerJsonUrlx = 'http://112.74.171.47:8080/Geojson/yunnan/yunyan/xiayan/3/';
	ב.fillLayerColor = null;

    ב.cityInfo = {
        "530000": {
            "name": "云南省",
            "borderUrl": "src/oneMap/config/boundary/state.json"
        }
    };

    function getMapAreaBoundary(areaCode, paramData) {
        let boundary = [],
            latArry = [],
            lonArry = [];

        // 循环分别提出经纬度
        let paramLent = paramData.length;
        for (let x = 0; x < paramLent; x++) {
            let paramLentx = paramData[x].length;
            for (let y = 0; y < paramLentx; y++) {
                let areaCodex = areaCode.toString();
                if (areaCodex.split("")[areaCodex.length - 1] > 0) {
                    latArry.push(Number(paramData[x][y].split(',')[1])); // 纬度
                    lonArry.push(Number(paramData[x][y].split(',')[0])); // 经度
                } else {
                    latArry.push(paramData[x][y][0]); // 纬度
                    lonArry.push(paramData[x][y][1]); // 经度
                }
            }
        }

        // 比较最大值、最小值
        let pointLent = latArry.length,
            latMax = latArry[0], latMin = latArry[0],
            lonMax = lonArry[0], lonMin = lonArry[0];
        for (let x = 0; x < pointLent; x++) {
            if (latArry[x] > latMax) {
                latMax = latArry[x];
            }

            if (latArry[x] < latMin) {
                latMin = latArry[x];
            }

            if (lonArry[x] > lonMax) {
                lonMax = lonArry[x];
            }

            if (lonArry[x] < lonMin) {
                lonMin = lonArry[x];
            }
        }

        boundary.push(latMin);
        boundary.push(lonMin);
        boundary.push(latMax);
        boundary.push(lonMax);

        return boundary;
    }

	// 初始化地图
	ב.map = new SuperMap.Map("map", {
        controls: [
            // 滚动条控制图层缩放
            new SuperMap.Control.Navigation(),
            // 键盘控制缩放平移
            new SuperMap.Control.KeyboardDefaults()
        ],
        allOverlays: true
    });

	// 实例化图层
    ב.layer1 = new SuperMap.Layer.Tianditu({"layerType": "vec"});
    ב.layer2 = new SuperMap.Layer.Tianditu({"layerType": "img"});
    ב.layer3 = new SuperMap.Layer.Tianditu({"layerType": "ter"});
    ב.layer5 = new SuperMap.Layer.Tianditu({"layerType": "vec", "isLabel":true});
    ב.layer6 = new SuperMap.Layer.Tianditu({"layerType": "img", "isLabel":true});
    ב.layer7 = new SuperMap.Layer.Tianditu({"layerType": "ter", "isLabel":true});
    ב.mapBounds = new SuperMap.Bounds(97.528700, 21.142651, 106.193900, 29.251751);

	// 添加图层
    ב.map.addLayers([
        ב.layer1,
    	ב.layer2,
    	ב.layer3,
        ב.layer5,
        ב.layer6,
        ב.layer7
    ]);

    // 设置中心点
    ב.map.zoomToExtent(ב.mapBounds, true);
    ב.map.zoomTo(6);

    // 图层初始显隐
    ב.layer2.setVisibility(false);
    ב.layer6.setVisibility(false);
    ב.layer3.setVisibility(false);
    ב.layer7.setVisibility(false);

	// 图层顺序定位
    ב.map.setLayerIndex(ב.layer1, 1);
    ב.map.setLayerIndex(ב.layer2, 2);
    ב.map.setLayerIndex(ב.layer3, 3);
    ב.map.setLayerIndex(ב.layer5, 5);
    ב.map.setLayerIndex(ב.layer6, 6);
    ב.map.setLayerIndex(ב.layer7, 7);
    
    // 清除重复图层
    ב.cleanMapLayersByName = function(layerName) {
        let layer = null,
            layers = ב.map.getLayersByName(layerName);
        if(layers != null && layers.length > 1){
            for(var i = 1; i < layers.length; i++){
                ב.map.removeLayer(layers[i], false);
            }
            if(layers[0] != null){
                layers[0].removeAllFeatures();
            }
            layer = layers[0];
        }else if(layers != null && layers.length ==1 && layers[0] != null){
            layers[0].removeAllFeatures();
            layer = layers[0];
        }else{
            layer = null;
        }
        return layer;
    }

    // 绘制边界
    ב.mapStroke = function(areaCode, param) {

        let url = null,
            areaCodex = areaCode.toString();
        if (areaCodex.split("")[areaCodex.length - 1] > 0) {
            url = ב.borderUrl;
        } else {
            url = param['borderUrl'];
        }

        $.ajax({
            url: url,
            type: "post",
            data: {code: areaCode},
            dataType: "json",
            success: function(result){
                let pointValue = result.data;
				if(pointValue != null && pointValue.bound != null && pointValue.bound.length > 0){
					//区域边界，考虑飞地
					let polygonArray = [];
					for(let a = 0; a < pointValue.bound.length; a++){
						let points = [],
							arr = pointValue.bound[a];
						for(let i = 0; i < arr.length; i++){
                            let p = null;
                            if (areaCodex.split("")[areaCodex.length - 1] > 0) {
                                p = new SuperMap.Geometry.Point(arr[i].split(",")[0],arr[i].split(",")[1]);
                            } else {
                                p = new SuperMap.Geometry.Point(arr[i][0],arr[i][1]);
                            }
							points.push(p);
						}
						let line = new SuperMap.Geometry.LinearRing(points);
						polygonArray.push(line);
					}

					let region = new SuperMap.Geometry.Polygon(polygonArray),
						regionVector = new SuperMap.Feature.Vector(region),
                        isAdd = false;
                    ב.vectorLayer = ב.cleanMapLayersByName('border_vector');
					if(ב.vectorLayer == null){
						isAdd = true;
						ב.vectorLayer = new SuperMap.Layer.Vector('border_vector', {renderers: ["Canvas"]});
					}
					regionVector.style = {
							strokeColor: '#ff0000',
							strokeWidth: 2,
							fill: false
					};
					ב.vectorLayer.addFeatures([regionVector]);

					if(isAdd){
						ב.map.addLayers([ב.vectorLayer]);
						ב.map.setLayerIndex(ב.vectorLayer, 3);
                    }

                    let latLon = getMapAreaBoundary(areaCode, pointValue.bound);

                    if (areaCodex.split("")[areaCodex.length - 1] > 0) {
                        ב.mapBounds = new SuperMap.Bounds(
                            latLon[1],
                            latLon[0],
                            latLon[3],
                            latLon[2]
                        );
                    } else {
                        ב.mapBounds = new SuperMap.Bounds(
                            latLon[0],
                            latLon[1],
                            latLon[2],
                            latLon[3]
                        );
                    }

                    if (areaCodex == "530000") {
                        ב.map.zoomToExtent(ב.mapBounds, true);
                        ב.map.zoomTo(6);
                    } else if (areaCodex.split("")[areaCodex.length - 1] > 0) {
                        ב.map.zoomToExtent(ב.mapBounds, true);
                        ב.map.zoomTo(10);
                    } else {
                        ב.map.zoomToExtent(ב.mapBounds, true);
                        ב.map.zoomTo(8);
                    }
				}
            }
        });
    }
    // 绘制行政边界
    ב.mapStroke(530000, ב.cityInfo["530000"]);

    // 获取JSON文件进行渲染
    ב.getLayerJson = function (path, layerId) {
        var jsonVector = ב.map.getLayersByName("layer_"+layerId)[0];
        if (jsonVector == "" || jsonVector == undefined) {
            jsonVector = new SuperMap.Layer.Vector("layer_"+layerId);
        }
        jsonVector.removeAllFeatures();
        ב.map.addLayers([jsonVector]);

        // 删除色标
        $(".wrap_colorCode > ul").empty();

        $.ajax({
            url : ב.getLayerJsonUrlx + '/' + path,
            type: "get",
            dataType : 'json',
            async: 'false',
            success: function(data) {
                if(data != null && data != ''){
                    // 获取色标
                    let codeList = "";
                    for (let x = 0; x < data[1]['items'].length; x++) {
                        let color = data[1]['items'][x]['FillStyle']['ForeColor'],
                            title = data[1]['items'][x].Caption;
                        if (x == 0) {
                            title = '<' + title;
                        } else if (x == data[1]['items'].length-1) {
                            title = '>=' + data[1]['items'][x-1].Caption;
                        } else {
                            title = data[1]['items'][x-1].Caption +'~'+ title;
                        }
                        codeList += "<li style='background-color: "+ color +"'>"+ title +"</li>";
                    }
                    $(".wrap_colorCode > ul").append(codeList);
                    // 开始进行渲染
                    var vArray = new Array();
                    $.each(data[2].features, function(idx1, regionItem){
                        var region;
                        var mulregions = new Array();
                        for(var i = 0;i < regionItem.geometry.coordinates.length; i++){
                            for(var k = 0; k < regionItem.geometry.coordinates[i].length; k++){
                                var curdata0 = regionItem.geometry.coordinates[i][k];
                                var points2 = new Array();
                                for(var j = 0;j < curdata0.length; j++){
                                    // 边界点
                                    points2[j] = new SuperMap.Geometry.Point(curdata0[j][0],curdata0[j][1]);
                                }
                                // 点划线
                                var line2 = new SuperMap.Geometry.LinearRing(points2);
                                mulregions[k]=line2;
                            }
                            // 用所有的线生成普通岛洞图
                            region = new SuperMap.Geometry.Polygon(mulregions);
                            var regionVector = new SuperMap.Feature.Vector(region),
                                MGMinValue = regionItem.properties.MGMinValue,
                                MGMaxValue = regionItem.properties.MGMaxValue;
                            // 给岛洞填色
                            if(MGMinValue <= -90){
                                MGMinValue = MGMaxValue;
                            }
                            for(var l = data[1].items.length-1; l >= 0; l--){
                                if (MGMinValue >= data[1].items[l].Value) {
                                    regionVector.style = {
                                        fillColor: data[1].items[l].FillStyle['ForeColor'],
                                        fillOpacity: 1,
                                        strokeWidth: 0
                                    };
                                    break;
                                }
                            }
                            vArray.push(regionVector);
                        }
                    });
                    jsonVector.addFeatures(vArray);
                    vArray = null;
                    ב.map.addLayers([jsonVector]);
                    jsonVector.setVisibility(true);
                    jsonVector.setOpacity(.6); // 设置透明度
                    ב.map.setLayerIndex(jsonVector, 9);
                    ב.map.setLayerIndex(ב.layer5, 9);
                    ב.map.setLayerIndex(ב.layer6, 9);
                    ב.map.setLayerIndex(ב.layer7, 9);
                    data = null;
                }
            },
            error: function(XHR) {
                $(".autoPlay").find('i').removeClass('fa-pause').addClass('fa-play');
                clearInterval(ב.autoPlay);
                ב.confirms("alert", "当前选择未查询到数据！", "");
            }
        });
    }
})(onemap);
	}
})